package PAT;

import java.util.*;

public class PAT1155 {
    private static final List<List<Integer>> ans = new ArrayList<>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] =scanner.nextInt();
        }
        int temp = traceBack(values,n,0,new ArrayList<Integer>());
        for (List<Integer> an : ans) {
            for (int i = 0; i < an.size(); i++) {
                System.out.print(an.get(i));
                if(i==an.size()-1){
                    System.out.println("");
                }else{
                    System.out.print(" ");
                }
            }
        }
        if(temp == 1) System.out.println("Max Heap");
        else if(temp == 2) System.out.println("Min Heap");
        else{
            System.out.println("Not Heap");
        }
    }

    private static int traceBack(int[] values, int n, int k, List<Integer> list) {
        list.add(values[k]);
        try{
            if(2*k+1>n-1){ // 如果已经没有左子树了，就放进去
                ans.add(new ArrayList<>(list));
                return 0; // 0表示可以大顶也可以小顶  -1表示不可能  1表示大顶  2表示小顶
            }else{
                if(2*k+2<=n-1){ //如果存在右子树
                    if(values[2*k+2]==values[k] && values[2*k+1]==values[k]){
                        return check(0,traceBack(values,n,2*k+1,list),traceBack(values,n,2*k+2,list));
                    }
                    if(values[2*k+2]<=values[k] && values[2*k+1]<=values[k]){
                        return check(1,traceBack(values,n,2*k+1,list),traceBack(values,n,2*k+2,list));
                    }
                    if(values[2*k+2]>=values[k] && values[2*k+1]>=values[k]){
                        return check(2,traceBack(values,n,2*k+1,list),traceBack(values,n,2*k+2,list));
                    }else{
                        return -1;
                    }
                }else{
                    if(values[2*k+1]==values[k]){
                        return check(0,traceBack(values,n,2*k+1,list),0);
                    }
                    if(values[2*k+1]<values[k]){
                        return check(1,traceBack(values,n,2*k+1,list),0);
                    }else{
                        return check(2,traceBack(values,n,2*k+1,list),0);
                    }
                }
            }
        }finally {
            list.remove(list.size()-1);
        }


    }

    private static int check(int i, int left, int right) {
        if(i==-1 || left==-1|| right==-1){
            return -1;
        }else{
            return i|left|right;
        }
    }


}
